/***********************************************************/
/**						sys_call.h by doom119		       */
/**							May, 2010					   */
/***********************************************************/
#ifndef _SYS_CALL_H_
#define _SYS_CALL_H_

#define NR_SYSTEM_CALLS 72

#define _SYSCALL_setup 0
#define _SYSCALL_exit 1
#define _SYSCALL_fork 2

extern int sys_setup();
extern int sys_exit();
extern int sys_fork();

typedef int (*fn_ptr)();
fn_ptr system_call_table[] = { sys_setup, sys_exit, sys_fork };

#define syscall0(type, name) \
	type name(void) \
	{ \
		long __res; \
		__asm__ volatile ("int $0x80\n\t" \
				:"=a"(__res) \
				:"0"(_SYSCALL_##name)); \
		if(__res >= 0) return (type)__res; \
		return -1; \
	}

#define syscall1(type, name, atype, a) \
	type name(atype aname) \
	{ \
		long __res; \
		__asm__ volatile ("int $0x80\n\t" \
				:"=a"(__res) \
				:"0"(_SYSCALL_##name), "b"((long)(a))); \
		if(__res >=0) return (type)__res; \
		return -1; \
	}

#define syscall2(type, name, atype, a, btype, b) \
	type name(atype a, btype, b) \
	{ \
		long __res; \
		__asm__ volatile ("int $0x80\n\t" \
				:"=a"(__res) \
				:"0"(_SYSCALL_##name), "b"((long)(a)), \
				"c"((long)(b))); \
		if(__res >= 0) return (type)__res; \
		return -1; \
	}

#define syscall3(type, name, atype, a, btype, b, ctype, c) \
	type name(atype a, btype b, ctype c) \
	{ \
		long __res; \
		__asm__ volatile ("int $0x80\n\t" \
				:"=a"(__res) \
				:"0"(_SYSCALL_##name), "b"((long)(a)), \
				"c"((long)(b)), "d"((long)(c))); \
		if(__res >= 0) return (type)__res; \
		return -1; \
	}

#endif
